<template>
	<view class="page">

		<view class="page-content ">
			<u-tabs :list="list" active-color="#F24646" :is-scroll="true" :current="current" @change="change"></u-tabs>
			<view class="line"></view>
			<view class="p12">

				<view class=" " v-for="(item,index) in dataList" :key="index">
					<view class="bg-white mb15 p10 u-flex" style="box-shadow: 0px 8px 20px 0px rgba(230,219,209,0.25);">
						
						<image v-if="item.img && item.img!='null'" :src="item.img" style="width:200rpx;height: 200rpx;" mode="aspectFill"></image>
						<view class="u-f1 pl10">
							<view class="fz14 u-f-jsb u-flex">{{item.propertyName}}<span class="status fz12">{{item.statusDec}}</span>
							</view>
							<view class="fz12 mt4 c9 u-line-1">{{item.detailedAddress}}</view>
							<view class="u-flex fz12 mt12">
								<span class="c6">房源类别</span>
								<span class="color-price ml6" style="color: #FBB03B;">{{item.categoryName}}</span>
							</view>
							<view class="u-flex fz12 u-f-jsb mt12" v-if="item.status==1 || item.status==5">
								<span class="c6"></span>
								<view class="u-flex">
									<view class="btn" @click="toEdit(item)">编辑</view>
									<view class="btn btn-del ml10" @click="toDel(index)">删除</view>
								</view>
							</view>
							<!-- <view class="u-flex fz12 mt5">
								<span class="c6">承包合约</span>
								<span class="color-price ml6">{{item.leaseStartDate}}-{{item.leaseEndDate}}</span>
							</view> -->
						</view>
					</view>

				</view>
			</view>
		</view>
		<u-loadmore :status="loadStatus"></u-loadmore>


	</view>
</template>

<script>
	export default {
		data() {
			return {
				current: 0,
				statusAttr: ['', '待签到', '已签到', '已取消'],
				list: [{
					name: '全部',
					id: '',
				}, {
					name: '待审核',
					id: '2'
				}, {
					name: '已审核未发布',
					id: '3'
				}, {
					name: '已发布',
					id: '4'
				}, {
					name: '已退回',
					id: '5'
				}, {
					name: '草稿',
					id: '1'
				}, ],
				cateList:[],
				loadStatus: 'more',
				scrollHeight: 300,
				dataList: [],
				page: 1,
			}
		},
		onLoad(e) {
			if (e.tab) {
				this.current = e.tab
			}
		},
		onShow() {
			this.$nextTick(() => {
				this.initData()
			})
			
			
			this.$api.notifyGetCategoryList({}, (res) => {
				if (res.code == 200) {
					this.cateList=res.data
				}
			})
		},
		// 页面下拉到底部触发
		onReachBottom() {
			if (this.loadStatus == 'more') {
				this.getData()
			}
		},
		methods: {
			toEdit(info){
				
					this.cateList.some(item=>{
						if(item.id==info.categoryId){
							
								uni.navigateTo({
									url: `/pages/house/add?frontDisplayFields=${item.frontDisplayFields}&id=${item.id}&curId=${info.id}`
								})
						}
					})
			},
			change(e) {
				this.current = e
				this.initData()
			},
			initData() {
				this.page = 1
				this.dataList = []
				this.getData()
			},
			
			toDel(idx){
				
							
					this.$common.modelShow('提示', '确认删除该数据吗?', () => {
						
						
						
							this.$api.cluemanagementDel({
								id: this.dataList[idx].id
							}, res => {
								if (res.code) {
									uni.showToast({
										title: '删除成功',
										icon: 'none'
									});
									this.dataList.splice(idx,1)
								}else{
									
									uni.showToast({
										title: res.message,
										icon: 'none'
									});
								}
							})
					});
							
			},
			getData() {
				this.$api.getMeHousing({
					pageNo: this.page,
					pageSize: 10,
					status: this.list[this.current].id
				}, res => {
					if (res.code) {
						res.data.list.some(item => {
							if(item.propertyImages){
								this.$set(item,'img',item.propertyImages.split(',')[0])
							}
							this.list.some(item1 => {
								if(item.status==item1.id){
									this.$set(item,'statusDec',item1.name)
								}
								
							})
						})
						let _list = res.data.list
						this.dataList = [...this.dataList, ..._list]
						// 判断所有数据是否请求完毕
						if (res.data.total > this.dataList.length) {
							this.page++
							this.loadStatus = 'more'
						} else {
							this.loadStatus = 'noMore'
						}
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.btn {
		padding: 0 30rpx;
		height: 60rpx;
		text-align: center;
		line-height: 60rpx;
			background: rgba(242, 70, 70, 0.1);
		color: #F24646;
		border-radius: 40px;
		&.btn-del{
			background: #f5f5f5;
			color: #999;
		}
	}

	.line {
		width: 750rpx;
		height: 4rpx;
		position: relative;
		top: -4rpx;
		background: #F6F9F9;
		border-radius: 0px 0px 0px 0px;
	}

	.status1 {
		color: #E54440;
	}

	.status2 {
		color: #39959B;
	}

	.status3 {
		color: #333;
	}
</style>